package qrcode

// 小程序码管理

import (
    "fmt"
	"wxsdk/miniapp/core"
	//"github.com/astaxie/beego"
)

const (
	urlWxAcode        = "https://api.weixin.qq.com/wxa/getwxacode?access_token=%s"
	urlWxAcodeUnlimit = "http://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token=%s"
)

type GetQrcodeRequest struct {
	Path      string  `json:"path"`
	Width     int     `json:"width"`
	AutoColor bool    `json:"auto_color"`
	LineColor struct {
		R     string `json:"r"`                    
		G     string `json:"g"`        
		B     string `json:"b"`
	} `json:"line_color,omitempty"`
}

// 获取小程序码，直达页面
func GetWxAcode(accessToken, path string,autoColor bool,r,g,b string) (body []byte, err error) {
	url := fmt.Sprintf(urlWxAcode, accessToken)
	client := core.GetPostJSONClient()
	var req = new(GetQrcodeRequest)
	req.Path = path
	req.Width = 430
	req.AutoColor = autoColor
	req.LineColor.R = r
	req.LineColor.G = g
	req.LineColor.B = b
	body, err = client.Excute("POST", url, req, nil)
	return
}

type GetWxAcodeUnlimitRequest struct {
	Scene     string  `json:"scene"`
	Page      string  `json:"page"`
	Width     int     `json:"width"`
	AutoColor bool    `json:"auto_color"`
	LineColor struct {
		R     string `json:"r"`                    
		G     string `json:"g"`        
		B     string `json:"b"`
	} `json:"line_color,omitempty"`
}

// 获取小程序码，直达首页
func GetWxAcodeUnlimit(accessToken, scene, page string,autoColor bool,r,g,b string,width int) (body []byte, err error) {
	url := fmt.Sprintf(urlWxAcodeUnlimit, accessToken)
	client := core.GetPostJSONClient()
	var req = new(GetWxAcodeUnlimitRequest)
	req.Scene = scene
	req.Page = page
	req.Width = width
	req.AutoColor = autoColor
	req.LineColor.R = r
	req.LineColor.G = g
	req.LineColor.B = b
	body, err = client.Excute("POST", url, req, nil)
	return
}
